<?php

include "../controller/ConectBanco.php";

class AlarmDAO{

	function delete($idalarm){
		$result = mysql_query("SELECT idDevice FROM alarm WHERE idAlarm = $idalarm")or die (mysql_error());
		$iddevice = mysql_fetch_array($result);
		mysql_query("DELETE FROM alarm WHERE idAlarm =".$idalarm) or die (mysql_error());

		header("location:../view/ListaAlarm.php?idDevice=".$iddevice['idDevice']);
	}

	function update(Alarm $alarm){

		mysql_query("UPDATE alarm SET combustEletric='".$alarm->getCombustEletric()."'
 									, tracking='".$alarm->getTracking()."'
 								    , alarm='".$alarm->getAlarm()."'
 									, charge='".$alarm->getCharge()."'
 		                            , acc='".$alarm->getAcc()."'
 		                            , `voltage`='".$alarm->getVoltage()."'
		 		                    , `signal`='".$alarm->getSignal()."'
 		                            , realDateTime='".$alarm->getRealDateTime()."'
 		                            , dateTime='".$alarm->getDateTime()."'
 		                            , latitude='".$alarm->getLatitude()."'
									, longitude='".$alarm->getLongitude()."'
									, velocidade=".$alarm->getVelocidade()."
									".($alarm->getEndereco() == null ? ",endereco=''" : "endereco='".$alarm->getEndereco()."'")."
									  WHERE idAlarm='".$alarm->getIdAlarm()."'") or die (mysql_error());
			
			

		header("location:../view/ListaAlarm.php?idDevice=".$alarm->getIdDevice());
	}
}

?>
